package com.cne.gmail.Gmail.Handle;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import lombok.extern.log4j.Log4j2;
import org.elasticsearch.action.search.SearchTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@ControllerAdvice
@Log4j2
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ModelAndView resolveException(Exception e) {
        ModelAndView mav = new ModelAndView();
        Map<String,Object> map = Maps.newHashMap();
        map.put("success",false);

        Set set= new HashSet();
        set.add(2);

      /*  if(e instanceof UnauthorizedException){
            map.put("msg","登录信息已过期!");
            map.put("code",ErrorCode.UNAUTHORIZED.name());
        } else if(e instanceof ServiceException){
            map.put("msg",e.getMessage());
            map.put("code",ErrorCode.B0001.name());
        }else {
            map.put("msg","系统异常,message = ["+e.getMessage()+"]");
            map.put("code", ErrorCode.SYSTEMERROR.name());
            LOGGER.error("GlobalExceptionHandler全局异常!",e);
        }*/
        MappingJackson2JsonView jackson2JsonView = new MappingJackson2JsonView();
        jackson2JsonView.setAttributesMap(map);
        mav.setView(jackson2JsonView);
        return mav;
    }

}
